package cn.com.zpark.servlet_config;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @PackageName: cn.com.zpark.servlet_config
 * @ClassName: ServletConfigDemo03
 * @Description:
 * @author: RZS
 * @date: 2021/11/10  17:38
 */
@WebServlet(urlPatterns = "/scd3.do", initParams = {
        @WebInitParam(name = "name", value = "张三"),
        @WebInitParam(name = "pwd", value = "123456")
})
public class ServletConfigDemo03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletConfig config = getServletConfig();
        // 获取初始化参数
        Enumeration<String> names = config.getInitParameterNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();// 初始化参数的名字
            String value = config.getInitParameter(name);
            System.out.println(name+": "+value);
        }
    }
}
